package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.common.enums.RoleEnum;
import com.example.springboot.entity.Account;
import com.example.springboot.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能:
 * 作者: whs
 * 日期:20241025 10:43:30
 */
@RestController
public class WebController {

    @Resource
    private AdminService adminService;

    /**
     * 默认请求接口
     */
    @GetMapping("/")
    public Result hello(){
        return Result.success();
    }

    /**
     * 登录
     * @param account
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Account account){
        Account loginAccount=null;
        if(RoleEnum.ADMIN.name().equals(account.getRole())){
            loginAccount = adminService.login(account);
        }
        return Result.success(loginAccount);
    }

    /**
     * 注册
     */
    @PostMapping("/register")
    public Result register(){

        return Result.success();
    }
}